﻿using SanJ.FreeCare.ValueSets;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Domain.Services;

namespace SanJ.FreeCare.CodeSystems
{
    public class CodeSystemManager : DomainService
    {
        private readonly ICodeSystemRepository _codeSystemRepository;
        public CodeSystemManager(ICodeSystemRepository codeSystemRepository) 
        { 
            this._codeSystemRepository = codeSystemRepository;
        }

        public async Task<CodeSystem> CreateAsync(CodeSystem codeSystem)
        {
            return await _codeSystemRepository.InsertAsync(codeSystem);
        }

        public async Task<CodeSystem> UpdateAsync(CodeSystem codeSystem)
        {
            return await _codeSystemRepository.UpdateAsync(codeSystem);
        }

        public async Task DeleteAsync(Guid id)
        {
            await _codeSystemRepository.DeleteAsync(id);
        }

        public async Task<List<CodeConcept>> GetAllAsync()
        {
            List<CodeConcept> result = new List<CodeConcept>();
            var codeSystemList = await _codeSystemRepository.GetListAsync();
            foreach (var item in codeSystemList)
            {
                result.AddRange(item.CodeConcepts);
            }
            return result;
        }
    }
}
